package com.ocom.company.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.company.EntityProductSuggestion;
import com.ocom.common.entity.master.EntityMngUserInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.common.request.company.ProductSuggestionRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.company.dao.IDaoProductSuggestion;
import com.ocom.company.service.ProductSuggestionService;
import com.ocom.mysql.aspect.DataSourceAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductSuggestionServiceImpl extends ServiceImpl<IDaoProductSuggestion, EntityProductSuggestion> implements ProductSuggestionService {


    @Override
    @DataSourceAspect(type = DataSourceEnum.MAIN_DB, isMaster = MasterSlaveEnum.SLAVE)
    public List<EntityProductSuggestion> productSuggestionList(Long comId, Long userId) {
        QueryWrapper<EntityProductSuggestion> queryWrapper = Wrappers.query();
        queryWrapper.eq("user_id", userId);
        return this.list(queryWrapper);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.MAIN_DB, isMaster = MasterSlaveEnum.MASTER)
    public Result productSuggestionCreate(Long comId, EntityProductSuggestion entityProductSuggestion) {
        this.save(entityProductSuggestion);
        return ResultUtil.success();
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.MAIN_DB, isMaster = MasterSlaveEnum.SLAVE)
    public List<EntityProductSuggestion> productSuggestionPage() {
        return this.list();
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.MAIN_DB, isMaster = MasterSlaveEnum.MASTER)
    public void productSuggestionUpdate(ProductSuggestionRequest request) {
        EntityProductSuggestion entityProductSuggestion = new EntityProductSuggestion();
        BeanUtil.copyProperties(request,entityProductSuggestion);
        this.updateById(entityProductSuggestion);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.MAIN_DB, isMaster = MasterSlaveEnum.MASTER)
    public void productSuggestionDelete(ProductSuggestionRequest request) {
        this.removeById(request.getId());
    }

}
